package com.wmm.controller;

import com.wmm.common.Product;
import com.wmm.common.ProductVo;
import com.wmm.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

@RestController
@RequestMapping("product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @Autowired
    private RestTemplate restTemplate;

    @PostMapping("insert")
    public String saveProdut(@RequestBody Product product) {

        productService.insert(product);
        return "id: " + product.getId();
    }

    @PostMapping("query")
    public Map queryByName(@RequestBody ProductVo productVo) {

        Map object = restTemplate.postForObject("http://127.0.0.1:9700/search/product", productVo, Map.class);
        return object;
    }
}
